#include<stdio.h>
#include <SDL/SDL_image.h>
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_mixer.h"
int main(int argc, char *argv[])
{
int continuer = 1 , i=0,pl=0,hs=0,sto=0,sett=0,qu=0;
SDL_Event event;
SDL_Surface* PLAY= NULL ,*SETTING = NULL , *STORE = NULL,*HIGH=NULL,*QUIT=NULL,* PLAY2= NULL ,*SETTING2 = NULL , *STORE2 = NULL,*HIGH2=NULL,*QUIT2=NULL,* ecran = NULL,*imagechat =NULL, *a = NULL  ,*a2 = NULL, *s = NULL ,*fond=NULL ;
Mix_Music* son;
son= Mix_LoadMUS("chat.ogg");
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024 ) == -1 ) { return 0; }
SDL_Rect positionFond ,positionp,positionp2,position,positiona ,positiona2,positions , posfond,posse,posst,posh,posq,posse2,posst2,posh2,posq2;
TTF_Init();
TTF_Font *police = NULL;
SDL_Color couleurNoire = {0,0,0};
SDL_Color couleurma = {120,30,30};
SDL_Color blanc= {255,255,255};


    
     posfond.x=0;
     posfond.y=5;
    positions.x = 800;
    positions.y = 0;
    positionFond.x = 0;
    positionFond.y = 0;
    positiona.x = 0;
    positiona.y = 500;
    positiona2.x = 0;
    positiona2.y = 500;    
   positionp.x = 270;
   positionp.y = 300;
   posse.x=50;
   posse.y=500;
   posst.x=400;
   posst.y=500;
   posh.x=200;	
   posh.y=400;
   posq.x=270;	
   posq.y=600;
   positionp2.x = 270;
   positionp2.y = 300;
   posse2.x=50;
   posse2.y=500;
   posst2.x=400;
   posst2.y=500;
   posh2.x=200;	
   posh2.y=400;
   posq2.x=270;	
   posq2.y=600;


    SDL_Init(SDL_INIT_VIDEO);

    //SDL_WM_SetIcon(SDL_LoadBMP("sdl_icone.bmp"), NULL);

    
    ecran = SDL_SetVideoMode(680, 700, 32, SDL_HWSURFACE);
    SDL_WM_SetCaption("TEST SDL", NULL);

    police = TTF_OpenFont("ComicPerso.ttf", 100);
   

     fond= IMG_Load("l7ofra3.jpg");
    SDL_BlitSurface(fond, NULL, ecran, &posfond);
PLAY= TTF_RenderText_Blended(police, "PLAY",couleurNoire);
  SDL_BlitSurface(PLAY, NULL, ecran , &positionp);   
SDL_Flip(ecran);
HIGH = TTF_RenderText_Blended(police, "HIGH SCORE", couleurNoire);    
  //SDL_BlitSurface(HIGH, NULL, ecran , &posh);  
STORE= TTF_RenderText_Blended(police, "STORE", couleurNoire);    
  //SDL_BlitSurface(STORE, NULL, ecran , &posst);     
SETTING= TTF_RenderText_Blended(police, "SETTING", couleurNoire);    
  //SDL_BlitSurface(SETTING, NULL, ecran , &posse);     
QUIT= TTF_RenderText_Blended(police, "QUIT", couleurNoire);    
  //SDL_BlitSurface(QUIT, NULL, ecran , &posq); 





PLAY2= TTF_RenderText_Blended(police, "PLAY", couleurma);    
 
HIGH2= TTF_RenderText_Blended(police, "HIGH SCORE", couleurma);    
  //SDL_BlitSurface(HIGH2, NULL, ecran , &posh);  
STORE2= TTF_RenderText_Blended(police, "STORE", couleurma);    
  //SDL_BlitSurface(STORE2, NULL, ecran , &posst);     
SETTING2= TTF_RenderText_Blended(police, "SETTING", couleurma);    
  //SDL_BlitSurface(SETTING2, NULL, ecran , &posse);     
QUIT2= TTF_RenderText_Blended(police, "QUIT", couleurma);    
  //SDL_BlitSurface(QUIT2, NULL, ecran , &posq);             
    //imagechat= SDL_LoadBMP("chat.bmp"); 
    //a = SDL_LoadBMP("chatbt.bmp");
    //SDL_BlitSurface(a, NULL, ecran, &positiona);
     //s = SDL_LoadBMP("play_sound.bmp");
    //SDL_BlitSurface(s, NULL, ecran, &positions);
a2= SDL_LoadBMP("chatbtClic.bmp");
    //SDL_Flip(ecran);
   
 
while (continuer)
{
    SDL_WaitEvent(&event);
    switch(event.type)
    {
        case SDL_QUIT:
            continuer = 0;
            break;
        case SDL_KEYDOWN: 
            continuer = 0;
            break;
    

 case SDL_MOUSEMOTION:                  //passage de la souris
            
            if ((event.motion.x>270)&&(event.motion.x<270+PLAY->w)&&(event.motion.y<300+PLAY->h)&&(event.motion.y>300))   //play
           {
             pl=1;
           SDL_BlitSurface(PLAY2, NULL, ecran , &positionp);
SDL_Flip(ecran);
           } else{ pl=0;    SDL_BlitSurface(PLAY, NULL, ecran , &positionp);   
SDL_Flip(ecran);}
          //passage de la souris
            
            if ((event.motion.x>200)&&(event.motion.x<270+HIGH ->w)&&(event.motion.y<400+HIGH->h)&&(event.motion.y>400))   //high score
           {
             hs=1;
           // break;
           } else{ hs=0;}            
            if ((event.motion.x>400)&&(event.motion.x<400+STORE->w)&&(event.motion.y<500+STORE->h)&&(event.motion.y>500))   //store
           {
             sto=1;
           // break;
           } else{ sto=0;}
          
            if ((event.motion.x>50)&&(event.motion.x<50+SETTING->w)&&(event.motion.y<500+SETTING->h)&&(event.motion.y>500))   //setting
           {
             sett=1;
           // break;
           } else{ sett=0;}           
            if ((event.motion.x>270)&&(event.motion.x<270+QUIT->w)&&(event.motion.y<600+QUIT->h)&&(event.motion.y>600))   //quit 
           {
             qu=1;
           // break;
           } else{ qu=0;}
break;

/*case SDL_MOUSEBUTTONUP:                  //clic souris
            
            if ((event.motion.x>270)&&(event.motion.x<300)&&(event.motion.y<320)&&(event.motion.y>300))   //chat
           {
        //    SDL_BlitSurface(PLAY2, NULL, ecran , &positionp2);  
            
            i=1;
               
           }
break;
          
}*/
if (pl==1)
{
SDL_BlitSurface(PLAY2, NULL, ecran , &positionp);
SDL_Flip(ecran);
}else{
SDL_BlitSurface(PLAY, NULL, ecran , &positionp);
SDL_Flip(ecran);
}

}
if (hs==1)
{
SDL_BlitSurface(HIGH2, NULL, ecran , &posh2);
}else{
SDL_BlitSurface(HIGH, NULL, ecran , &posh);
}
SDL_Flip(ecran);

if (sett==1)
{
SDL_BlitSurface(SETTING2, NULL, ecran , &posse2);
}else{
SDL_BlitSurface(SETTING, NULL, ecran , &posse);
}
SDL_Flip(ecran);

if (sto==1)
{
SDL_BlitSurface(STORE2, NULL, ecran , &posst2);
}else{
SDL_BlitSurface(STORE, NULL, ecran , &posst);
}
SDL_Flip(ecran);

if (qu==1)
{
SDL_BlitSurface(QUIT2, NULL, ecran , &posq2);
}else{
SDL_BlitSurface(QUIT, NULL, ecran , &posq);
}
SDL_Flip(ecran);
}

 
    TTF_CloseFont(police);
    TTF_Quit();
SDL_FreeSurface(imagechat);
    SDL_FreeSurface(a);
    SDL_Quit();

    return EXIT_SUCCESS;
}
